﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business;
using ZLCMS.Data.Model;
using System.Text;
using System.Collections;
using NHibernate.Criterion;
using ZLCMS.Business.DwzFrame;
using System.Reflection;
using NHibernate;
using ZLCMS.Business.Util;

namespace ZLCMS.Web.SystemManage.Basics.MessageBoard
{
    public partial class MessageReplyQuick : System.Web.UI.Page
    {
        protected FrameHelper _framePage;

        protected MessageInfo _messageDB;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            //初始化全局变量值
            InitializeGlobalValue();

            //初始化控件值
            InitializeContent();

            //初始化DWZ控件
            _framePage = new FrameHelper(this);

            if (IsPostBack)
            {
                Save();
            }
        }

        protected void InitializeGlobalValue()
        {
            int id;

            try
            {
                if (!IsPostBack)
                {
                    id = int.Parse(Request["uid"]);

                    _id.Text = id.ToString();
                }
                else
                {
                    id = int.Parse(_id.Text);
                }

                using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
                {
                    _messageDB = session.Get<MessageInfo>(id);
                }

                if (_messageDB == null)
                {
                    throw new Exception("找不到对应信息.");
                }
            }
            catch (System.Exception ex)
            {
                _framePage.Alert(new ReturnCode() { statusCode = 300, message = "操作出错-" + ex.Message });
                return;
            }
        }

        protected void InitializeContent()
        {
            //页面控件数据
            ParamKit.Bind("YesNo_10", ddl_status, null, null, null, "-1", null);


            //页面控件值
            if (!IsPostBack)
            {
                ddl_status.SelectedValue = _messageDB.Status;
            }
        }

        protected void Save()
        {
            _messageDB.Status = ddl_status.SelectedValue;

            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                session.Update(_messageDB);
                session.Flush();
            }

            _framePage.Alert(new ReturnCode()
            {
                statusCode = 200,
                message = "操作成功!",
                callbackType = "closeCurrent",
                navTabId = _framePage.NavTabId
            });
        }
    }
}
